#pragma rtGlobals=3		// Use modern global access method.
#include "Chamber_initialisation"
Window init_panel() : Panel
	PauseUpdate; Silent 1		// building window...
	NewPanel /W=(504,45,705,248)
	Button LogBinCuts,pos={9,8},size={128,16},proc=ButtonProc_MuList,title="Set log bin cuts"
	Button LogBinCuts,font="Lucida Grande"
	SetVariable D_lowest,pos={16,32},size={136,15},proc=SetVarProc_Dlow,title="lowest diameter (nm)"
	SetVariable D_lowest,value= _NUM:10
	SetVariable D_highest,pos={16,53},size={154,15},proc=SetVarProc_Dhigh,title="largest diameter (nm)"
	SetVariable D_highest,value= _NUM:500
	SetVariable numbins,pos={17,72},size={119,15},proc=SetVarProc_NumBins,title="number of bins"
	SetVariable numbins,value= _NUM:16
	Button LoadSpeciesList,pos={9,99},size={127,16},proc=ButtonProc_GetSpeciesList,title="Get species list"
	Button LoadSpeciesList,font="Lucida Grande"
	Button BulkDensity,pos={8,157},size={137,16},proc=ButtonProc_BulkDensity,title="Calc bulk density"
	Button BulkDensity,font="Lucida Grande"
	Button GetSpcDensity,pos={9,118},size={160,16},proc=ButtonProc_SpeciesDensities,title="Get species densities"
	Button GetSpcDensity,font="Lucida Grande"
	Button LoadPredAeroConc,pos={9,137},size={154,16},proc=ButtonProc_PredAeroConc,title="Load pred aero conc"
	Button LoadSmiles,pos={10,175},size={162,20},proc=ButtonProc_LoadApineneSMILEs,title="load apinene SMILEs"
	Button LoadSmiles,font="Lucida Sans"
EndMacro

Function ButtonProc_MuList(ba) : ButtonControl
	STRUCT WMButtonAction &ba

	switch( ba.eventCode )
		case 2: // mouse up
			controlinfo D_lowest
			variable D_lowest=V_value
			controlinfo D_highest
			variable D_highest=V_value
			controlinfo NumBins
			variable NumBins=V_value
			mulist(D_lowest,D_highest,NumBins)// click code here
			set_r_r(D_lowest)
			break
		case -1: // control being killed
			break
	endswitch

	return 0
End
Function SetVarProc_Dlow(sva) : SetVariableControl
	STRUCT WMSetVariableAction &sva

	switch( sva.eventCode )
		case 1: // mouse up
		case 2: // Enter key
		case 3: // Live update
			Variable dval = sva.dval
			String sval = sva.sval
			break
		case -1: // control being killed
			break
	endswitch

	return 0
End


Function SetVarProc_Dhigh(sva) : SetVariableControl
	STRUCT WMSetVariableAction &sva

	switch( sva.eventCode )
		case 1: // mouse up
		case 2: // Enter key
		case 3: // Live update
			Variable dval = sva.dval
			String sval = sva.sval
			break
		case -1: // control being killed
			break
	endswitch

	return 0
End

Function SetVarProc_NumBins(sva) : SetVariableControl
	STRUCT WMSetVariableAction &sva

	switch( sva.eventCode )
		case 1: // mouse up
		case 2: // Enter key
		case 3: // Live update
			Variable dval = sva.dval
			String sval = sva.sval
			break
		case -1: // control being killed
			break
	endswitch

	return 0
End


Function ButtonProc_GetSpeciesList(ba) : ButtonControl
	STRUCT WMButtonAction &ba

	switch( ba.eventCode )
		case 2: // mouse up
			SpecListFromFile()
			// click code here
			break
		case -1: // control being killed
			break
	endswitch

	return 0
End


Function ButtonProc_SpeciesDensities(ba) : ButtonControl
	STRUCT WMButtonAction &ba

	switch( ba.eventCode )
		case 2: // mouse up
			// click code here
			NewSubPath("ChemistryScheme","AerosolChemistryScheme","aerosol",OverwritePath=1)
			wave/T OrganicSpecies
			GetSpcDensity(OrganicSpecies)
			break
		case -1: // control being killed
			break
	endswitch

	return 0
End

Function ButtonProc_BulkDensity(ba) : ButtonControl
	STRUCT WMButtonAction &ba

	switch( ba.eventCode )
		case 2: // mouse up
			// click code here
			wave/T OrganicSpecies
			GetMolarMass(OrganicSpecies) // get molar masses
			if(!waveexists($"PredAeroConc"))
				DoAlert/T="FAIL!" 0,"PredAeroConc does not exist.\rPlease make this wave and try again."
				Abort
			endif
			wave PredAeroConc,MolarMass_OrganicSpecies
			wave/T OrganicSpecies
			PredMassCheck(PredAeroConc,OrganicSpecies,MolarMass_OrganicSpecies,OrganicSpecies)
			
			wave/T AeroSpecName=OrganicSpecies
			wave SpecDensity=OrganicSpecies_density
			wave SpecMass=PredAeroMass // made by PredMassCheck 
			BulkDensity(AeroSpecName,SpecDensity,SpecMass)
			break
		case -1: // control being killed
			break
	endswitch

	return 0
End

Function ButtonProc_PredAeroConc(ba) : ButtonControl
	STRUCT WMButtonAction &ba

	switch( ba.eventCode )
		case 2: // mouse up
			// click code here
//			LoadWave/O/A/J/D/K=0/B="N=PredAeroConc;" "Clipboard" // loads aerosol species concentrations predicted by Dave's partition code
			load_EqSpeciesConc()
			wave PredAeroConc
//			note/k PredAeroConc, "molecules/cc"
			break
		case -1: // control being killed
			break
	endswitch

	return 0
End


Function ButtonProc_LoadApineneSMILEs(ba) : ButtonControl
	STRUCT WMButtonAction &ba

	switch( ba.eventCode )
		case 2: // mouse up
			SMILEs_loadapinene()
			// click code here
			break
		case -1: // control being killed
			break
	endswitch

	return 0
End